<@override name="content">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15"  id="app">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">拼团商品搜索</div>
                <div class="layui-card-body">
                   <!-- <div class="alert alert-success alert-dismissable">
                        <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                        目前拥有4个秒杀商品
                    </div>-->
                    <form class="layui-form">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">搜　　索：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="goodsName" lay-verify="goodsName" style="width: 100%" autocomplete="off" placeholder="请输入商品名称,关键字,编号" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">秒杀状态：</label>
                                <div class="layui-input-inline">
                                    <select name="isShow" lay-verify="isShow">
                                        <option value="">全部</option>
                                        <option value="1">开启</option>
                                        <option value="0">关闭</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="search" style="font-size:14px;line-height: 9px;">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索</button>
                            </label>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">拼团商品列表</div>
                <div class="layui-card-body">
                    <div class="layui-btn-container">
                        <a class="layui-btn layui-btn-sm" onclick="$eb.createModalFrame(this.innerText,'${request.contextPath}/admin/groupGoods/modify',{h:700,w:1000});">添加拼团商品</a>
                    </div>
                    <table class="layui-hide" id="seckillList" lay-filter="seckillList"></table>
                    <script type="text/html" id="isShow">
                        <input type='checkbox' name='isShow' lay-skin='switch' value="{{d.id}}" lay-filter='isShow' lay-text='开启|关闭'  {{ d.isShow == 1 ? 'checked' : '' }}>
                    </script>
                    <script type="text/html" id="barDemo">
                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作<span class="caret"></span></button>
                        <ul class="layui-nav-child layui-anim layui-anim-upbit">
                            <li>
                                <a href="javascript:void(0);" onclick="$eb.createModalFrame('{{d.goodsName}}-编辑','${request.contextPath}/admin/groupGoods/modify?id={{d.id}}')"><i class="layui-icon layui-icon-edit"></i> 编辑活动</a>
                            </li>
                            <li>
                                <a href="javascript:void(0);" class="delstor" lay-event='delstor'><i class="layui-icon layui-icon-delete"></i> 删除</a>
                            </li>
                        </ul>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${request.contextPath}/js/layuiList.js"></script>
<script src="${request.contextPath}/js/content.min.js?v=1.0.0"></script>
<script>
    layList.form.render();
    layList.tableList('seckillList',"${request.contextPath}/admin/groupGoods/listData",function () {
        return [
            {field: 'id', title: 'ID', sort: true,width:'6%',event:'id'},
            {field: 'goodsImage', title: '商品图片', width: '10%',templet: '<p><img src="{{d.goodsImage}}" alt="{{d.goodsName}}" class="open_image" data-image="{{d.goodsImage}}"></p>'},
            {field: 'goodsName', title: '商品名称'},
            {field: 'webGoodsPrice', title: '原价',width:'6%'},
            {field: 'webGroupPrice', title: '组团价',width:'6%'},
            {field: 'num', title: '限量',width:'6%'},
            {field: 'stock', title: '库存',width:'6%'},
            {field: 'sales', title: '已售',width:'6%'},
            {field: 'endTime', title: '结束时间', width: '8%'},
            {field: 'isShow', title: '状态',width:'8%',toolbar:"#isShow"},
            {field: 'right', title: '操作',width:'10%', align: 'center', toolbar: '#barDemo'}
        ]
    });
    layList.tool(function (event,data,obj) {
        switch (event) {
            case 'delstor':
                var url = '${request.contextPath}/admin/groupGoods/delete?id='+data.id;
                $eb.$swal('delete',function(){
                    $eb.axios.post(url).then(function(res){
                        if(res.data.code == 200) {
                            $eb.$swal('success',res.data.msg);
                            obj.del();
                        }else
                            return Promise.reject(res.data.msg || '删除失败')
                    }).catch(function(err){
                        $eb.$swal('error',err);
                    });
                })
                break;
        }
    })
    $(document).click(function (e) {
        $('.layui-nav-child').hide();
    })
    function dropdown(that){
        var oEvent = arguments.callee.caller.arguments[0] || event;
        oEvent.stopPropagation();
        var offset = $(that).offset();
        var top=offset.top-$(window).scrollTop();
        var index = $(that).parents('tr').data('index');
        $('.layui-nav-child').each(function (key) {
            if (key != index) {
                $(this).hide();
            }
        })
        if($(document).height() < top+$(that).next('ul').height()){
            $(that).next('ul').css({
                'padding': 10,
                'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
                'min-width': 'inherit',
                'position': 'absolute'
            }).toggle();
        }else{
            $(that).next('ul').css({
                'padding': 10,
                'top':$(that).parent('td').height() / 2 + $(that).height(),
                'min-width': 'inherit',
                'position': 'absolute'
            }).toggle();
        }
    }
    layList.search('search',function(where){
        layList.reload(where);
    });
    layList.search('export',function(where){
        location.href=layList.U({c:'ump.store_seckill',a:'save_excel',q:{status:where.status,store_name:where.store_name}});
    })
    layList.switch('isShow',function (odj,value,name) {
        if (odj.elem.checked == true) {
            var url ="${request.contextPath}/admin/groupGoods/updateIsShow/1/"+value;
            layList.baseGet(url, function (res) {
                layList.msg(res.msg);
            }, function () {
            });
        } else {
            var url ="${request.contextPath}/admin/groupGoods/updateIsShow/0/"+value;
            layList.baseGet(url, function (res) {
                layList.msg(res.msg);
            }, function () {
            });
        }
    })
    $('.js-group-btn').on('click',function(){
        $('.js-group-btn').css({zIndex:1});
        $(this).css({zIndex:2});
    });
    $('#delstor').on('click',function(){
        window.t = $(this);
        var _this = $(this),url =_this.data('url');
        $eb.$swal('delete',function(){
            $eb.axios.get(url).then(function(res){
                console.log(res);
                if(res.status == 200 && res.data.code == 200) {
                    $eb.$swal('success',res.data.msg);
                    _this.parents('tr').remove();
                }else
                    return Promise.reject(res.data.msg || '删除失败')
            }).catch(function(err){
                $eb.$swal('error',err);
            });
        })
    });
    $(document).on('click',".open_image",function (e) {
        var image = $(this).data('image');
        $eb.openImage(image);
    });
</script>


</@override>
<@extends name="../public/container.html"/>